package cn.sciento.transfer.infra.datasource.factory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import cn.sciento.transfer.infra.constant.Constants;
import cn.sciento.transfer.infra.datasource.ddl.MySqlTableScriptBuilder;
import cn.sciento.transfer.infra.datasource.ddl.OracleTableScriptBuilder;
import cn.sciento.transfer.infra.datasource.ddl.SqlServerTableScriptBuilder;
import cn.sciento.transfer.infra.datasource.ddl.TableScriptBuilder;
import org.springframework.util.Assert;

public class TableScriptBuilderFactory {
  private static TableScriptBuilderFactory factory = new TableScriptBuilderFactory();
  
  private static Map<String, TableScriptBuilder> builderMap = new ConcurrentHashMap<>();
  
  static {
    builderMap.put(Constants.DabaseName.mysql.name(), new MySqlTableScriptBuilder());
    builderMap.put(Constants.DabaseName.oracle.name(), new OracleTableScriptBuilder());
    builderMap.put(Constants.DabaseName.sqlserver.name(), new SqlServerTableScriptBuilder());
  }
  
  public static TableScriptBuilderFactory getInstance() {
    return factory;
  }
  
  public TableScriptBuilder creator(String dabaseName) {
    TableScriptBuilder createTableScriptBuilder = builderMap.get(dabaseName);
    Assert.isTrue((createTableScriptBuilder != null), "error for unsupported database type");
    return createTableScriptBuilder;
  }
}
